package cn.bouncyslime.graduationProject.nba.crawler.pipeline;

import cn.bouncyslime.graduationProject.nba.dao.PlayerDataDao;
import cn.bouncyslime.graduationProject.nba.dto.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import us.codecraft.webmagic.ResultItems;
import us.codecraft.webmagic.Task;
import us.codecraft.webmagic.pipeline.Pipeline;

import java.util.List;

/**
 * @author 张一卓
 * @date 2020/4/3 0:00
 **/
@Component
public class PS_PlayerDataPipeLine implements Pipeline {
    @Autowired
    PlayerDataDao playerDataDao;

    @Override
    public void process(ResultItems resultItems, Task task) {
        List<PS_PlayerAveragingDto> list = resultItems.get("PS_playerAveragingDataList");
        if (list != null){
            for (PS_PlayerAveragingDto dto : list){
                playerDataDao.insertPSPlayerAveragingData(dto);
            }
        }
        List<PS_PlayerSummaryDto> list2 = resultItems.get("PS_playerSummaryDataList");
        if (list2 != null){
            for (PS_PlayerSummaryDto dto : list2) {
                playerDataDao.insertPSPlayerSummaryData(dto);
            }
        }
        List<PlayerSingleTopmostDto> list3 = resultItems.get("PS_playerSingleDataList");
        if (list3 != null){
            for (PlayerSingleTopmostDto dto : list3){
                playerDataDao.insertPSPlayerSingleTopmostData(dto);
            }
        }
        List<PlayerAdvancedBasicDto> list4 = resultItems.get("PS_playerAdvancedBasicDataList");
        if (list4 != null){
            for (PlayerAdvancedBasicDto dto : list4){
                playerDataDao.insertPSPlayerAdvancedBasicData(dto);
            }
        }
        List<PlayerAdvancedShootingDto> list5 = resultItems.get("PS_playerAdvancedShootingDataList");
        if (list5 != null){
            for (PlayerAdvancedShootingDto dto : list5){
                playerDataDao.insertPSPlayerAdvancedShootingData(dto);
            }
        }
    }
}
